package coml.jiyun.hp.zuoye.model;

import coml.jiyun.hp.zuoye.bean.WanBean;
import coml.jiyun.hp.zuoye.callback.WanCallBack;
import coml.jiyun.hp.zuoye.net.WanServer;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class ImpWanModel implements WanModel {
    @Override
    public void getData(WanCallBack wanCallBack) {
        new Retrofit.Builder()
                .baseUrl(WanServer.baseUrl)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(WanServer.class)
                .getData()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<WanBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(WanBean wanBean) {
                        wanCallBack.onSuccess(wanBean);
                    }

                    @Override
                    public void onError(Throwable e) {
                        wanCallBack.onFail(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
